package be.credoc.underlying.address.business.entity;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(schema = "SPIKE", name = "EnglishWord")
public class EnglishWord {
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "englishWordId")
	private Integer id;

	@Column(name = "word")
	private String word;
	
	@OneToMany(mappedBy = "englishWord", cascade = CascadeType.ALL)
	private List<Translation> translations = new ArrayList<Translation>(1);
	
	public EnglishWord() {
	}

	public EnglishWord(String word) {
		this.word = word;
	}

	public Integer getId() {
		return id;
	}

	public String getWord() {
		return word;
	}

	public void setWord(String word) {
		this.word = word;
	}

	public List<Translation> getTranslations() {
		return translations;
	}

	public void setTranslations(List<Translation> translations) {
		this.translations = translations;
	}

	public void add(Translation translation) {
		translations.add(translation);		
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((word == null) ? 0 : word.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		EnglishWord other = (EnglishWord) obj;
		if (word == null) {
			if (other.word != null)
				return false;
		} else if (!word.equals(other.word))
			return false;
		return true;
	}
}
